package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.business.domain.*;
import com.ruoyi.business.service.IBusContractService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.service.IBusContractReminderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同催款Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@RestController
@RequestMapping("/business/reminder")
public class BusContractReminderController extends BaseController
{
    @Autowired
    private IBusContractReminderService busContractReminderService;

    @Autowired
    private IBusContractService busContractService;

    /**
     * 查询合同催款列表
     */
   // @PreAuthorize("@ss.hasPermi('business:reminder:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusContractReminder busContractReminder)
    {
        startPage();
        List<BusContractReminder> list = busContractReminderService.selectBusContractReminderList(busContractReminder);
        return getDataTable(list);
    }

    /**
     * 查询合同催款列表(index 页面接口)
     */
   // @PreAuthorize("@ss.hasPermi('business:reminder:listContractReminder')")
    @GetMapping("/listContractReminder")
    public TableDataInfo listContractReminder(BusContractReminderParam busContractReminderParam)
    {
        startPage();
        List<BusContractReminderDetail> list = busContractReminderService.getContractReminderList(busContractReminderParam);
        return getDataTable(list);
    }

    /**
     * 导出合同催款列表
     */
   // @PreAuthorize("@ss.hasPermi('business:reminder:export')")
    @Log(title = "合同催款", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusContractReminder busContractReminder)
    {
        BusContract busContract = busContractService.selectBusContractByContractId(busContractReminder.getContractId());
        List<BusContractReminder> list = busContractReminderService.selectBusContractReminderList(busContractReminder);
        ExcelUtil<BusContractReminder> util = new ExcelUtil<BusContractReminder>(BusContractReminder.class);
        return util.exportExcel(list, "合同编号【"+busContract.getContractNo()+"】催款信息");
    }

    /**
     * 获取合同催款详细信息
     */
   // @PreAuthorize("@ss.hasPermi('business:reminder:query')")
    @GetMapping(value = "/{reminderId}")
    public AjaxResult getInfo(@PathVariable("reminderId") Long reminderId)
    {
        return AjaxResult.success(busContractReminderService.selectBusContractReminderByReminderId(reminderId));
    }

    /**
     * 新增合同催款
     */
   // @PreAuthorize("@ss.hasPermi('business:reminder:add')")
    @Log(title = "合同催款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusContractReminder busContractReminder)
    {
        busContractReminder.setCreateBy(getUsername());
        return toAjax(busContractReminderService.insertBusContractReminder(busContractReminder));
    }

    /**
     * 修改合同催款
     */
   // @PreAuthorize("@ss.hasPermi('business:reminder:edit')")
    @Log(title = "合同催款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusContractReminder busContractReminder)
    {
        busContractReminder.setUpdateBy(getUsername());
        return toAjax(busContractReminderService.updateBusContractReminder(busContractReminder));
    }

    /**
     * 删除合同催款
     */
   // @PreAuthorize("@ss.hasPermi('business:reminder:remove')")
    @Log(title = "合同催款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reminderIds}")
    public AjaxResult remove(@PathVariable Long[] reminderIds)
    {
        return toAjax(busContractReminderService.deleteBusContractReminderByReminderIds(reminderIds));
    }
}
